package com.ruoyi.web.controller.asset;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AssetStandardConfiguration;
import com.ruoyi.asset.service.IAssetStandardConfigurationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标准配置Controller
 * 
 * @author ruoyi
 * @date 2023-04-06
 */
@Controller
@RequestMapping("/asset/configuration")
public class AssetStandardConfigurationController extends BaseController
{
    private String prefix = "asset/configuration";

    @Autowired
    private IAssetStandardConfigurationService assetStandardConfigurationService;

    @RequiresPermissions("asset:configuration:view")
    @GetMapping()
    public String configuration()
    {
        return prefix + "/configuration";
    }

    /**
     * 查询标准配置列表
     */
    @RequiresPermissions("asset:configuration:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AssetStandardConfiguration assetStandardConfiguration)
    {
        startPage();
        List<AssetStandardConfiguration> list = assetStandardConfigurationService.selectAssetStandardConfigurationList(assetStandardConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出标准配置列表
     */
    @RequiresPermissions("asset:configuration:export")
    @Log(title = "标准配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AssetStandardConfiguration assetStandardConfiguration)
    {
        List<AssetStandardConfiguration> list = assetStandardConfigurationService.selectAssetStandardConfigurationList(assetStandardConfiguration);
        ExcelUtil<AssetStandardConfiguration> util = new ExcelUtil<AssetStandardConfiguration>(AssetStandardConfiguration.class);
        return util.exportExcel(list, "标准配置数据");
    }

    /**
     * 新增标准配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存标准配置
     */
    @RequiresPermissions("asset:configuration:add")
    @Log(title = "标准配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AssetStandardConfiguration assetStandardConfiguration)
    {
        return toAjax(assetStandardConfigurationService.insertAssetStandardConfiguration(assetStandardConfiguration));
    }

    /**
     * 修改标准配置
     */
    @RequiresPermissions("asset:configuration:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AssetStandardConfiguration assetStandardConfiguration = assetStandardConfigurationService.selectAssetStandardConfigurationById(id);
        mmap.put("assetStandardConfiguration", assetStandardConfiguration);
        return prefix + "/edit";
    }

    /**
     * 修改保存标准配置
     */
    @RequiresPermissions("asset:configuration:edit")
    @Log(title = "标准配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AssetStandardConfiguration assetStandardConfiguration)
    {
        return toAjax(assetStandardConfigurationService.updateAssetStandardConfiguration(assetStandardConfiguration));
    }

    /**
     * 删除标准配置
     */
    @RequiresPermissions("asset:configuration:remove")
    @Log(title = "标准配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(assetStandardConfigurationService.deleteAssetStandardConfigurationByIds(ids));
    }
}
